﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.popups.levelup {
    import flash.events.*;
    import flash.display.*;
    import reprise.controls.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.popups.*;
    import net.wooga.pets.constants.*;

    public class LevelUpPopupMediator extends AbstractPopupMediator {

        public var languageModel:LanguageModel;
        public var tickModel:TickModel;
        public var userModel:UserModel;
        public var environmentModel:EnvironmentModel;

        override public function onRegister():void{
            super.onRegister();
            this.view.respondsButton.addEventListener(MouseEvent.CLICK, this.onOk);
            this.view.setLanguage(this.environmentModel.language);
            this.levelUp();
        }
        private function get view():LevelUpPopupView{
            return ((viewComponent as LevelUpPopupView));
        }
        override protected function onOk(_arg1:MouseEvent):void{
            var _local2:LabelButton = LabelButton(_arg1.currentTarget);
            if (_local2.data() == LevelUpPopupView.BUTTON_SHARE_ID){
                dispatch(new InfoEvent(EventConstants.POST_ON_WALL, null, {type:GameConstants.POST_LEVEL_UP}));
            } else {
                super.onOk(_arg1);
            };
        }
        override protected function handlePostOnWallResult(_arg1:Boolean, _arg2:String):void{
            if (_arg2 == GameConstants.POST_LEVEL_UP){
                close();
            };
        }
        private function levelUp():void{
            var _local1:Object = this.view.data.level_info;
            var _local2:String = _local1.graphic_key;
            var _local3:String = this.whatYouGet(_local1);
            this.clearCSSClasses();
            this.view.addCSSClass(_local2);
            this.view.titleLabel = this.languageModel.getTextByKey(_local1.title_key);
            this.view.descriptionLabel = this.languageModel.getTextByKey(_local1.description_key);
            this.view.youGetLabel = _local3;
            this.view.level = int(_local1.level);
            this.loadAsset(_local2.toLowerCase());
            l(("graphicKey: " + _local2));
            if ((((((((_local2 == "LevelUpRehaSport")) || ((_local2 == "LevelUpKiosk")))) || ((_local2 == "LevelUpKindergarten")))) || ((_local2 == "LevelUpFountain")))){
                this.view.setResponseButtonLabel(this.languageModel.getTextByKey("global_build_now"), LevelUpPopupView.BUTTON_BUILD_ID);
            } else {
                this.view.setResponseButtonLabel(this.languageModel.getTextByKey("global_button_share"), LevelUpPopupView.BUTTON_SHARE_ID);
            };
        }
        private function loadAsset(_arg1:String):void{
            var _local2:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onResult);
            _local2.addAssetRequest(ProtocolConstants.LOAD_LEVELUP, _arg1);
            dispatch(_local2);
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:MovieClip;
            if (_arg1.success){
                _local2 = (_arg1.data[ProtocolConstants.LOAD_LEVELUP] as MovieClip);
                if (_local2){
                    this.view.addLevelUpAnimation(_local2);
                };
            };
        }
        private function whatYouGet(_arg1:Object):String{
            var _local2:String = _arg1.graphic_key;
            var _local3:String = _local2.substring(7);
            _local3 = _local3.toLowerCase();
            l(("whatYouGet = " + _local3));
            if ((((((((_local3 == "rehasport")) || ((_local3 == "kiosk")))) || ((_local3 == "kindergarten")))) || ((_local3 == "fountain")))){
                return (this.languageModel.getTextByKey(("room_" + _local3)));
            };
            if (_local3 == "coinsbag"){
                return (this.languageModel.getTextByKey("global_amount_coins", {amount:_arg1.level_up_coins}));
            };
            if (_local3 == "roomslot"){
                return (this.languageModel.getTextByKey("levelup_room_slot"));
            };
            if (_local3 == "boost"){
                return (this.languageModel.getTextByKey("levelup_increase_maxboost"));
            };
            return (this.languageModel.getTextByKey(("pet_" + _local3)));
        }
        private function clearCSSClasses():void{
            this.view.removeCSSClass(this.view.cssClasses);
        }

    }
}//package net.wooga.pets.views.popups.levelup 
